import os
from pdf2docx import Converter


class PDFToWord:
    def tudo(self,path):
        docx_path = path + "/docx"

        files = os.listdir(path)
        pdf_list = [file for file in files if file.endswith(".pdf")]

        pdf_path = [path + "/" + filename for filename in pdf_list]
        pdf_name = [filename for filename in pdf_list]
        if not os.path.exists(docx_path):
            os.mkdir(docx_path)
        print(os.path.exists(docx_path))
        print(pdf_name)
        for pdf in pdf_name:
            print("正在处理..."+ pdf)
            output = pdf.replace(".pdf", ".docx")
            # print(docx_path + "/" + output)
            cv = Converter(path + "/" + pdf)
            cv.convert(docx_path + "/" + output)
            cv.close()



if __name__ == '__main__':
    pdfToWord = PDFToWord()
    path = input("输入文件夹路径：")
    pdfToWord.tudo(path)
    input("处理完成！")
